package com.example.system.controller;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.classroom.dto.ClassroomSaveDTO;
import com.example.system.domain.classroom.dto.ClassroomQueryDTO;
import com.example.system.domain.classroom.vo.ClassroomDetailVO;
import com.example.system.domain.classroom.vo.ClassroomSelectVO;
import com.example.system.service.IClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/classroom")
public class ClassroomController extends BaseController {
    @Autowired
    private IClassroomService classroomService;

    @GetMapping("/list")
    public TableDataInfo list(ClassroomQueryDTO classroomQueryDTO) {
        return getTableDataInfo(classroomService.list(classroomQueryDTO));
    }

    //  /classroom/add
    @PostMapping("/add")
    public R<Void> add(@RequestBody ClassroomSaveDTO classroomAddDTO) {
        return toR(classroomService.add(classroomAddDTO));
    }

    //  /classroom/detail
    @GetMapping("/detail")
    public R<ClassroomDetailVO> detail(Long classroomId) {
        return R.ok(classroomService.detail(classroomId));
    }

    //  /classroom/edit
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ClassroomSaveDTO classroomSaveDTO) {
        return toR(classroomService.edit(classroomSaveDTO));
    }

    //  /classroom/delete
    @DeleteMapping("/delete")
    public R<Void> delete(Long classroomId) {
        return toR(classroomService.delete(classroomId));
    }

    @GetMapping("/selectList")
    public R<List<ClassroomSelectVO>> selectList(){
        return R.ok(classroomService.selectList());
    }
}
